package com.gxitsky.plugin.servlet3;

import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebListener;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author gxing
 * @desc TODO
 * @date 2022/1/6
 */
@WebListener
public class MyAsyncListener implements AsyncListener {
    @Override
    public void onComplete(AsyncEvent event) throws IOException {
        System.out.println("MyAsyncListener onComplete");
    }

    @Override
    public void onTimeout(AsyncEvent event) throws IOException {
        System.out.println("MyAsyncListener onTimeout");
        ServletResponse response = event.getAsyncContext().getResponse();
        PrintWriter out = response.getWriter();
        out.write("TimeOut 处理超时了!");

    }

    @Override
    public void onError(AsyncEvent event) throws IOException {
        System.out.println("MyAsyncListener onError");

    }

    @Override
    public void onStartAsync(AsyncEvent event) throws IOException {
        System.out.println("MyAsyncListener onStartAsync");

    }
}
